import { Injectable, Inject, CACHE_MANAGER } from '@nestjs/common';
import { Cache } from 'cache-manager';

@Injectable()
export class RedisService {
    constructor(
        @Inject(CACHE_MANAGER)
        private cacheManager: Cache
    ) {
    }

    cacheSet(key: string, value: string) {
        console.log("redis 测试！！");
        this.cacheManager.set(key, value, { ttl: 60 * 60 * 24 }, (err: any) => {  // ttl基础单位是秒
            if (err) {
                throw err;
            }
        })
    }

    async cacheGet(key: any): Promise<any> {
        return this.cacheManager.get(key);
    }
}
